#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e5+10;
int a[N];
int b[N];
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b); 
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		for(int i=1;i<=n;i++)
		{
			cin>>b[i];
		}
		int st[2]={0,0};
		
		for(int i=1;i<=n;i++)
		{
			if(a[i]==0 && b[i]==0) continue;
			if(b[i]==0)
			{
				st[1]=1;
				continue;
			}
			if(a[i]==0)
			{
				st[0]=1;
				continue;
			}
			int t=0;
			if(a[i]<b[i])
			{
				int c=b[i]-a[i];
				a[i]=b[i];
				b[i]=c;
				t++;
			}
			
			ll ans=ceil(a[i]*1.5/gcd(a[i],b[i]));
			ans+=t;
//			
			cout<<ans<<endl;
			st[ans%2]=1;
		}
		if(st[1]*st[0]) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}

